package com.xm.httpapi.Aspect;


import com.xm.httpapi.BaseUtils.ThreadPool;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Author:guohaijin
 * Date:
 * Description:
 */
@Aspect
public class AsyncAspect {
    private static final String POINTCUT_METHOD = "execution(@com.xm.httpapi.Annotation.Async * *(..))";


    @Around("onAsyncMethod()")
    public void doAsyncMethod(final ProceedingJoinPoint joinPoint) throws Throwable {
        asyncMethod(joinPoint);
    }

    @Pointcut(POINTCUT_METHOD)
    public void onAsyncMethod() { }

    private void asyncMethod(final ProceedingJoinPoint joinPoint) throws Throwable {
        ThreadPool.getIntance().execute(() -> {
            try {
                joinPoint.proceed();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        });
    }
}
